<template>
	<view>
		<view class="login">
			<view class="head">
				用户注册
			</view>
			<view>
				<form>
					<view class="cu-form-group">
						<view class="title">账号</view>
						<input placeholder="请输入账号" @input="theAccount()" v-model="userAccount">
					</view>
					<view class="cu-form-group">
						<view class="title">密码</view>
						<input placeholder="请输入密码" password="true" @input="thePassword()" v-model="userPassword">
					</view>
					<view class="cu-form-group">
						<view class="title">姓名</view>
						<input placeholder="请输入姓名" @input="theName()" v-model="userName">
					</view>
					<view class="cu-form-group">
						<view class="title">身份证号(选填)</view>
						<input placeholder="请输入身份证号" @input="theSfz()" v-model="sfz">
					</view>
				</form>
				<view style="margin-top: 20px;text-align: center;position: relative;">
					<button class="cu-btn round lg bg-yellow" @click="register()">注册</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import store from '@/store/index.js'; //需要引入store
	export default {
		data() {
			return {
				userAccount: '',
				userPassword: '',
				userName: '',
				sfz: ''
			}
		},
		methods: {
			theAccount: function(e) {
				this.userAccount = e.target.value
			},
			thePassword: function(e) {
				this.userPassword = e.target.value
			},
			theSfz: function(e) {
				this.sfz = e.target.value
			},
			theName: function(e) {
				this.userName = e.target.value
			},
			register() {
				console.log(this.userAccount)
				uni.request({
					url: 'http://172.20.10.5:8080/user/register',
					header: {
						'content-type': 'application/json',
					},
					data: {
						userAccount: this.userAccount,
						userPassword: this.userPassword,
						userName: this.userName,
						sfz: this.sfz
					},
					method: 'POST',
					header: {
						'content-type': 'application/json',
					},
					sslVerify: false,
					success: (res) => {
						console.log(res)
						if (res.data != 0) {
							uni.navigateTo({
								url: '../login/login'
							})
						} else {
							uni.showToast({
								title: '参数不能为空',
								icon: 'error'
							})
						}
					}
				})
			}
		}
	}
</script>

<style>
	.head {
		font-size: 20px;
		font-weight: 700;
		text-align: center;
		margin: 40rpx;
	}
</style>
